package com.bw.lyc.mvp.view.mine;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bw.lyc.R;
import com.bw.lyc.mvp.model.db.DBManager;
import com.bw.lyc.mvp.model.db.UserEntityDao;
import com.bw.lyc.mvp.model.entity.UserEntity;
import com.bw.lyc.util.StatusBarColorUtils;
import com.bw.lyc.util.StatusBarUtils;

public class UpdateActivity extends StatusBarColorUtils implements View.OnClickListener {

    private ImageView updateBack;
    private TextView updateEdit;
    private ImageView updateHeadIv;
    private TextView updateHeadName;
    private TextView updateHeadLv;
    private ImageView updateBgImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update);
        initView();

        try {
            UserEntity unique = DBManager.getInstance().getDaoSession().queryBuilder(UserEntity.class).where(UserEntityDao.Properties.Id.eq(0)).unique();
            String user_name = unique.getUser_name();
            int user_integral = unique.getUser_integral();
            String user_img = unique.getUser_img();
            Glide.with(this).load(user_img).into(updateBgImg);
            Glide.with(this).load(user_img).circleCrop().into(updateHeadIv);
            Intent intent = new Intent();
            intent.setAction("headImg");
            intent.putExtra("headImg", user_img);
            sendBroadcast(intent);

            Intent intent1 = new Intent();
            intent1.setAction("username");
            intent1.putExtra("username", user_name);
            sendBroadcast(intent1);
            updateHeadName.setText(user_name);
            updateHeadLv.setText("LV." + user_integral);
            StatusBarUtils.with(this)
                    .init();
        } catch (Exception e) {
            e.printStackTrace();
        }
        updateBack.setOnClickListener(this::onClick);
        updateEdit.setOnClickListener(this::onClick);


    }

    private void initView() {
        updateBack = (ImageView) findViewById(R.id.update_back);
        updateEdit = (TextView) findViewById(R.id.update_edit);
        updateHeadIv = (ImageView) findViewById(R.id.update_head_iv);
        updateHeadName = (TextView) findViewById(R.id.update_head_name);
        updateHeadLv = (TextView) findViewById(R.id.update_head_lv);
        updateBgImg = (ImageView) findViewById(R.id.update_bg_img);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.update_back) {
            finish();
        }
        if (id == R.id.update_edit) {
            startPage(UpdateUserActivity.class);
            finish();
        }
    }

    @Override
    public View addStatusView() {
        return f(R.id.update_relative);
    }
}